package learn.configuration;

import learn.bean.Person;
import learn.configuration.autowired.MyAutoWrite;
import learn.factoryBean.ColorFactoryBean;
import learn.initializingBean.Cat;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

/**
 * TODO
 *
 * @author FengQing
 * @date 2023/2/11 16:56
 * 以前配置文件的方式被替换成了配置类，即配置类==配置文件
 */
// 这个配置类也是一个组件
@Configuration // 告诉Spring这是一个配置类
@ComponentScan({"learn.configuration.scan","learn.configuration.autowired"})
public class MainConfig {




	// @Bean注解是给IOC容器中注册一个bean，类型自然就是返回值的类型，id默认是用方法名作为id
    // refresh()-> invokeBeanFactoryPostProcessors() ->invokeBeanDefinitionRegistryPostProcessors()
    // ->BeanDefinitionRegistryPostProcessor#postProcessBeanDefinitionRegistry -> processConfigBeanDefinitions()->loadBeanDefinitions(configClasses)
    // ->loadBeanDefinitionsForConfigurationClass()【处理@Bean、@ImportResource】 -> loadBeanDefinitionsForBeanMethod() -> registerBeanDefinition()
    // ->finishBeanFactoryInitialization()-> createBean()
	@Bean
	public Person person() {
		return new Person("liayun", 20);
	}
    @Bean
    public ColorFactoryBean colorFactoryBean() {
        return new ColorFactoryBean();
    }

    @Bean
    public Cat cat() {
        return new Cat();
    }
}